package com.google.servicedemo;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.Process;
import android.os.RemoteException;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.Log;

/**
 * Created by GR on 2017/12/13.
 * E-mail:android_gr@163.com
 * function:
 */

public class MyService extends Service {


    private NotificationManager systemService;
//    private MyBind mBind = new MyBind();
    IMyAidlInterface.Stub mBind = new IMyAidlInterface.Stub() {
        @Override
        public int plus(int a, int b) throws RemoteException {
            return a+b;
        }

        @Override
        public String toUpperCase(String str) throws RemoteException {
            if (str!=null){
                return str.toUpperCase();
            }
            return null;
        }
    };

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {

        Log.e("mrgao","MyService onBind()");
        return mBind;
    }

    @RequiresApi(api = 26)
    @Override
    public void onCreate() {
        super.onCreate();
        systemService = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        Log.e("mrgao","MyService onCreate()");

        Log.e("mrgao", "process id is " + Process.myPid());
//        try {
//            Thread.sleep(60000);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
       /* Notification.Builder builder = new Notification.Builder(this);
        builder.setTicker("提示");
        builder.setContentTitle("service通知");
        builder.setContentText("service转换成为前台运行");
        builder.setSmallIcon(R.mipmap.ic_launcher);
        Intent intent = new Intent(this,MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
        Notification notification = builder.build();
        systemService.notify(1,notification);*/

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e("mrgao","MyService onStartCommand()");
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        Log.e("mrgao","MyService onDestroy()");
    }

    class MyBind extends Binder{

        public void startDownLoad(){
            Log.e("mrgao","MyService startDownLoad()");
        }

    }
}
